package com.atguigu.admin.service.impl;

import com.atguigu.admin.service.UserService;
import com.atguigu.clients.UserClient;
import com.atguigu.param.CartListParam;
import com.atguigu.param.PageParam;
import com.atguigu.pojo.User;
import com.atguigu.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * ClassName:UserServiceImpl
 * Package:com.atguigu.admin.service.impl
 * Description:
 *
 * @Author 应永豪
 * @Create 2024/4/23 11:17
 * @Version 1.0
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserClient userClient;
    @Override
    @Cacheable(value = "list.user" ,key = "#param.currentPage+'-'+#param.pageSize")
    public R userList(PageParam param) {
        R r = userClient.adminListPage(param);
        log.info("UserServiceImpl.userList业务执行完毕，结果为：{}",r);
        return r;
    }

    @Override
    @CacheEvict(value = "list.user",allEntries = true)//清空缓存
    public R userRemove(CartListParam cartListParam) {
        R r = userClient.adminRemove(cartListParam);
        log.info("UserServiceImpl.userRemove业务执行完毕，结果为：{}",r);
        return r;
    }

    @Override
    @CacheEvict(value = "list.user",allEntries = true)//清空缓存
    public R userUpdate(User user) {
        R r = userClient.adminUpdate(user);
        log.info("UserServiceImpl.userUpdate业务执行完毕，结果为：{}",r);
        return r;
    }

    @Override
    @CacheEvict(value = "list.user",allEntries = true)//清空缓存
    public R userSave(User user) {
        R r = userClient.adminSave(user);
        log.info("UserServiceImpl.userSave业务执行完毕，结果为：{}",r);
        return r;
    }
}
